package com.feiyu.stackqueue;

import java.util.Random;

/**
 * @Author nanshouxiao@teacher.com.cn
 * @Date 2017-10-27 16:04
 */
public class StackQueueTest {
    public static void main(String[] args) {
        testProrityQueue();
    }

    private static void testStack() {
        String str = "I am Feiyu127";
        BaseStackQueue<Character> stack = new Stack<>(str.length());
        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }
        while (!stack.isEmpty()) {
            System.out.print(stack.pop());
        }
    }

    private static void testQueue() {
        String str = "I am Feiyu127";
        BaseStackQueue<Character> stack = new Queue<>(str.length());
        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }
        while (!stack.isEmpty()) {
            System.out.print(stack.pop());
        }
    }

    private static void testBaseQueue() {
        String str = "i am feiyu127, now i am test something";
        BaseQueue<Character> queue = new BaseQueue<>(2);
        for (int i = 0; i < str.length(); i++) {
            if (!queue.isFull() && i%5 > 0) {
                queue.push(str.charAt(i));
                continue;
            }
            while (!queue.isEmpty()) {
                System.out.print(queue.pop());
            }
        }
        System.out.println(queue.position());
    }

    private static void testProrityQueue() {
        Random random = new Random(10);
        int size = 20;
        BaseQueue<Integer> queue = new PriorityQueue<>(size);
        for(int i = 0; i < size - 2;i++) {
            int r = random.nextInt(100);
            queue.push(r);
            System.out.print(r);
            System.out.print(",");
        }
        System.out.println();
        while (!queue.isEmpty()) {
            System.out.print(queue.pop());
            System.out.print(",");
        }
    }
}
